package framework;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ExcelProcessor {

	public static Map<Integer, List> getExcelData(String filePath) {
		System.out.println("Excel Processing Started:");
		Map<Integer, List> mapValue = new HashMap();
		try {
			InputStream myxls = new FileInputStream(filePath);
			HSSFWorkbook wb = new HSSFWorkbook(myxls);
			HSSFSheet sheet = wb.getSheetAt(0);
			int row_count = sheet.getPhysicalNumberOfRows();
			HSSFRow row = sheet.getRow(0);
			int cell_count = row.getPhysicalNumberOfCells();
			for (int j = 1; j < row_count; j++) {
				mapValue.put(j, new ArrayList());
			}

			for (int i = 1; i < row_count; i++) {
				List list = mapValue.get(i);
				row = sheet.getRow(i);
				for (int j = 0; j < cell_count; j++) {
					HSSFCell cell = row.getCell(j);
					String cellvalue = cell != null ? cell.getStringCellValue()
							: "";
					list.add(cellvalue);
				}

			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// workbook wb= new HSS
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return mapValue;

	}

}
